﻿using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using WebPart = System.Web.UI.WebControls.WebParts.WebPart;

namespace TL.WeatherWebPart.WeatherWebPart
{
    [ToolboxItemAttribute(false)]
    public partial class WeatherWebPart : WebPart
    {
        #region properties

        private string _location = string.Empty;
        [Personalizable(), WebPartStorage(Storage.Shared), WebBrowsable(),
        WebDisplayName("Location"), WebDescription("Please specify location(e.g. 'Sydney')")]
        public string Location
        {
            get
            {
                return this._location;
            }
            set
            {
                this._location = value;
            }
        }



        #endregion
        // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
        // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
        // for production. Because the SecurityPermission attribute bypasses the security check for callers of
        // your constructor, it's not recommended for production purposes.
        // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
        public WeatherWebPart()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            hfLocation.Value = Location;
            CssLink cssLink = new CssLink();
            cssLink.DefaultUrl = SPUtility.ConcatUrls(SPContext.Current.Site.Url, "/Style Library/jqueryweather.css");
            this.Page.Header.Controls.Add(cssLink);
        }
    }
}
